$(document).ready(function () {
    var getUrl = "http://api.shur.cn/v1/ranking/total_credits?access_token=e3f9595e4559bceeda28514ba624b7ca290229c1&num=50&start=1";
    if (checkUrl(getUrl)) {
        get(getUrl, 'GET', {
            loading: function () {
                console.log('加载中。。。');
            },
            success: function (data) {
                console.log('回调-data:' + data);
                init(data);
            },
            error: function () {
                console.log('加载失败');
            }
        })
    }

    function init(data) {
        var rankings = data.rankings;
        console.log(rankings);
        $.each(rankings, function (index, item) {
            console.log(index + ":" + item);
            var integral = rankings[index].ranking;//等级
            var user = rankings[index].user;//用户信息
            var avatar_hd = user.avatar_hd;//用户头像
            var screen_name = user.screen_name;//用户姓名
            var group_title = user.group_title;//用户等级
            var credits = user.credits;//用户积分
            console.log('integral:' + integral + '，user：' + user);
            if (index < 3) {
                //设置前三名信息
                if (index == 0) {
                    $('#user-avatar-one-img').attr('src', avatar_hd);
                    $('#user-grade-one-num').text(index + 1);
                    $('#user-name-one').text(screen_name);
                    $('#user-grade-one').text(group_title);
                    $('#user-integral-one-text').text(credits);
                } else if (index == 1) {
                    $('#user-avatar-two-img').attr('src', avatar_hd);
                    $('#user-grade-two-num').text(index + 1);
                    $('#user-name-two').text(screen_name);
                    $('#user-grade-two').text(group_title);
                    $('#user-integral-two-text').text(credits);
                } else if (index == 2) {
                    $('#user-avatar-three-img').attr('src', avatar_hd);
                    $('#user-grade-three-num').text(index + 1);
                    $('#user-name-three').text(screen_name);
                    $('#user-grade-three').text(group_title);
                    $('#user-integral-three-text').text(credits);
                }


            } else {
                //设置后三名的信息
                var grade = index + 1;
                var avatarId = "avatar-id-" + (index + 1);
                var val = ' <li class="col-12">\n' +
                    '            <div class="ranking-list-item-ranking-number">\n' +
                    '                ' + grade + '\n' +
                    '            </div>\n' +
                    '            <img src="img/pic_login_portrait_boy.png" class="ranking-list-item-avatar" id=' + avatarId + '>\n' +
                    '            <div class="ranking-list-item-user-address">\n' +
                    '                <p>' + screen_name + '</p>\n' +
                    '                <p>' + group_title + '</p>\n' +
                    '            </div>\n' +
                    '            <div class="ranking-list-item-integral">' + credits + '</div>\n' +
                    '        </li>';
                $('#' + avatarId).attr('src', avatar_hd);
                $('#ranking-list-ul').append(val);

            }
        })
    }

    $('#btn-up-app').click(function () {
        console.log("app-btn-click");
        // var scheme = "scheme://host/pathPrefix?id=44";
        var scheme = "scheme://host/pathPrefix";
        startApp(scheme);
    });
});